package com.jonluo.controller;

import com.jonluo.rabbit.sender.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/rabbit")
public class RabbitTestController {

    @Autowired
    private HelloSender helloSender;

    @Autowired
    private HelloSender2 helloSender2;

    @Autowired
    private UserSender userSender;

    @Autowired
    private TopicSender topicSender;

    @Autowired
    private FanoutSender fanoutSender;


    /**
     * 单生产者-单消费者
     */
    @RequestMapping("/oneToOne")
    public String oneToOne() {
        helloSender.send();
        return "OK";
    }

    /**
     * 单生产者-多消费者
     */
    @RequestMapping("/oneToMany")
    public String oneToMany() {
        for(int i=0;i<10;i++){
            helloSender.send("hello:"+i);
        }
        return "OK";
    }

    /**
     * 多生产者-多消费者
     */
    @RequestMapping("/manyToMany")
    public String manyToMany() {
        for(int i=0;i<10;i++){
            helloSender.send("hello:"+i);
            helloSender2.send("hello:"+i);
        }
        return "OK";
    }

    /**
     * 实体类传输测试
     * springboot完美的支持对象的发送和接收，不需要格外的配置
     */
    @RequestMapping("/user")
    public String user() {
        userSender.send();
        return "OK";
    }


    /**
     * TopicExchange类型rabbitmq测试
     */
    @RequestMapping("/topic")
    public String topic() {
        topicSender.send();
        return "OK";
    }


    /**
     * FanoutExchange类型rabbitmq测试
     */
    @RequestMapping("/fanout")
    public String fanout() {
        fanoutSender.send();
        return "OK";
    }
}